from fastapi import APIRouter
from nation.models import *
from common import *

api = APIRouter()


@api.post("/page", summary="分页列表", description="分页列表")
async def page(params: PageParams):
    page = nation_page(params)
    return ApiResult(data=page)


@api.post("", summary="国家保存", description="国家保存")
async def save(item: NationDto):
    num = insert_nation(item)
    return ApiResult(data=num)


@api.put("", summary="国家更新", description="国家更新")
async def update(item: NationDto):
    num = update_nation(item)
    return ApiResult(data=num)


@api.delete("/{id}", summary="国家删除", description="国家删除")
async def delete(id: int):
    num = delete_nation(id)
    return ApiResult(data=num)


@api.get("/{id}", summary="国家详情", description="国家详情")
async def info(id: int):
    item = get_nation(id)
    return ApiResult(data=item)
